package org.gdstash.character;

import org.gdstash.file.GDReader;
import org.gdstash.file.GDWriter;

import java.io.IOException;

public class GDCharItemSkill {
    private String name;
    private String autoCastSkill;
    private String autoCastController;
    private int itemSlot;
    private String itemID;

    public void read() throws IOException {
        this.name = GDReader.readEncString();
        this.autoCastSkill = GDReader.readEncString();
        this.autoCastController = GDReader.readEncString();
        this.itemSlot = GDReader.readEncInt(true);
        this.itemID = GDReader.readEncString();
    }

    public void write() throws IOException {
        GDWriter.writeString(this.name);
        GDWriter.writeString(this.autoCastSkill);
        GDWriter.writeString(this.autoCastController);
        GDWriter.writeInt(this.itemSlot);
        GDWriter.writeString(this.itemID);
    }

    public int getByteSize() {
        int size = 0;
        size += 4;
        if (this.name != null) {
            size += this.name.length();
        }
        size += 4;
        if (this.autoCastSkill != null) {
            size += this.autoCastSkill.length();
        }
        size += 4;
        if (this.autoCastController != null) {
            size += this.autoCastController.length();
        }
        size += 4;
        size += 4;
        if (this.itemID != null) {
            size += this.itemID.length();
        }
        return size;
    }
}
